var senderDict = {};
var rx = /^\d\d:\d\d\s+(.+?)\s+-\s+.*$/;
function fillSender(xml, feed){
	var titles = xml.selectNodes("/rss/channel/item/title");

	for(var i=0; i<titles.length; i++){
		var m = titles[i].text.match(rx);
		if (!m)
			continue;
			
		senderDict[m[1]] = true;
	}
}

function fetch(){
	var feeds = ["tv2015.xml", "tvjetzt.xml", "tv2200.xml","tvtipps-spielfilm.xml"];
	for(var i=0; i<feeds.length; ++i){

		var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlHttp){
			xmlHttp.open('GET', 'http://www.tvmovie.de/rss/'+feeds[i], false);
			xmlHttp.onreadystatechange = function () {
				if (xmlHttp.readyState == 4 && xmlHttp.responseXML) {
					fillSender(xmlHttp.responseXML, feeds[i]);
				}
			};
			xmlHttp.send(null);
		}
	}
}
function readFile(path, charset) {
	try {
		var stream = new ActiveXObject("ADODB.Stream");

		stream.Charset = charset;
		stream.Open();
		stream.LoadFromFile(path);

		var result = stream.ReadText();
		stream.close();

		return result;
	} catch (ex) {
		return null;
	}
}
function writeFile(path, charset, text) {
	try {
		var stream = new ActiveXObject("ADODB.Stream");

		stream.Charset = charset;
		stream.Open();
		stream.WriteText(text);

		stream.SaveToFile(path,2);

	} catch (ex) {
		return null;
	}
}

function readFileJs(file){
	var scr = readFile(file, "utf-8");
	var arr = eval("("+scr+")");
	
	for(var i=0; i<arr.length; ++i)
		senderDict[arr[i]] = true;
}

function writeFileJs(file, text){
	writeFile(file, "utf-8", text);
}

function toArray(){
	var result = [];
	for(var n in senderDict){
		result.push(n);
	}
	return result;
}

readFileJs(currentView.files[currentView.file].replace("_updater.js",".js"));

fetch();

var result = '["'+toArray().sort().join('","')+'"]';

writeFileJs(currentView.files[currentView.file].replace("_updater.js",".js"), result);

alert(result);